<template>
	<view>
		<view v-if="!userInfo" style="width: 100%; height: 200px; margin-top: 100px; text-align: center;">
			<view style="font-size: 20px; margin-bottom: 50px;">对不起，请先进行支付宝授权登录</view>
			<button @click="getAuthCode" style="margin: 20px;" type="primary">支付宝授权登录</button>
			<!-- <button open-type="getAuthorize"
				scope="userInfo"
				onGetAuthorize="getOpenUserInfo" style="margin: 20px;" type="primary">支付宝授权登录</button> -->
		</view>
		<view v-if="userInfo && !dataList.length"
			style="width: 100%; height: 200px; margin-top: 100px; text-align: center;">
			<view style="font-size: 20px; margin-bottom: 50px;">对不起，暂无任何订单</view>
		</view>
		<view v-if="userInfo && dataList.length" style="padding: 20px;">
			<view v-for="(item,index) in dataList">
				<view class="itemLi">
					<view style="flex: 1;">
						状态：
					</view>
					<view>
						{{item.status_text}}
					</view>
				</view>
				<view class="itemLi">
					<view style="flex: 1;">
						授权金额：
					</view>
					<view>
						{{item.money}}元
					</view>
				</view>
				<view class="itemLi">
					<view style="flex: 1;">
						授权单号：
					</view>
					<view>
						{{item.orderSn}}
					</view>
				</view>
				<view class="itemLi">
					<view style="flex: 1;">
						授权时间：
					</view>
					<view>
						{{item.payTime_text}}
					</view>
				</view>
				<!-- <view class="itemLi">
					<view style="flex: 1;">
						租车车牌：
					</view>
					<view>
						{{item.orderInfo.carNumber}}
					</view>
				</view>
				<view class="itemLi">
					<view style="flex: 1;">
						租车车型：
					</view>
					<view>
						{{item.orderInfo.vehicleSnapshotInfo.showVmodelName}}
					</view>
				</view>
				<view class="itemLi">
					<view style="flex: 1;">
						用车人：
					</view>
					<view>
						{{item.orderInfo.lesseeName}}/{{item.orderInfo.lesseeMobile}}
					</view>
				</view>
				<view class="itemLi">
					<view style="flex: 1;">
						用车开始时间：
					</view>
					<view>
						{{item.orderInfo.pickTime_text}}
					</view>
				</view>
				<view class="itemLi">
					<view style="flex: 1;">
						用车结束时间：
					</view>
					<view>
						{{item.orderInfo.returnTime_text}}
					</view>
				</view> -->
				<view class="itemLi">
					<view style="flex: 1;">
						用车状态：
					</view>
					<view>
						{{item.orderInfo.status_text}}
					</view>
				</view>
				<view style="height: 5px; background-color: #dedede; margin-top: 10px; margin-bottom: 10px;"></view>
			</view>
		</view>
		<!-- <uni-popup ref="alertDialog" type="dialog">
				<uni-popup-dialog type="info" cancelText="关闭" 
				confirmText="进行登录" 
				title="登录" content="请先进项授权登录后再操作" @confirm="dialogConfirm"></uni-popup-dialog>
		</uni-popup> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userInfo: null,
				dataList: []
			}
		},
		onShow() {
			let userInfo = uni.getStorageSync('userInfo');
			if (typeof userInfo != 'undefined' || userInfo) {
				this.userInfo = userInfo
				if(this.userInfo.user_id) {
					this.getOrder()
				}
			}
		},
		methods: {
			getOrder() {
				let _this = this;
				_this.$httpSend({
					path: '/api/v1/alipay/order/freeze',
					data: {
						userId: _this.userInfo.user_id
					},
					success: (data) => {
						uni.hideLoading()
						_this.dataList = data;
					}
				});
			},
			getAuthCode() {
				let _this = this;
				//获取用户信息和AuthCode
				my.getAuthCode({
					scopes: 'auth_user',
					success: function(res) {
						if (typeof res.authCode != 'undefined') {
							uni.showLoading({
								title: '授权中...'
							})
							_this.$httpSend({
								path: '/api/v1/alipay/user/userInfo',
								data: {
									authCode: res.authCode
								},
								success: (data) => {
									uni.hideLoading()
									_this.userInfo = data;
									_this.getOrder()
									uni.setStorageSync('userInfo', data)
								}
							});
						}
					},
					fail: function(res) {
						uni.showToast({
							title: '授权失败',
							icon: 'error',
						})
					}
				});
			}
		}
	}
</script>

<style>
	.itemLi {
		width: 100%;
		display: flex;
		margin-bottom: 5px;
		font-size: 14px;
	}
</style>